var t = getApp(), a = t.requirejs("core"), e = t.requirejs("biz/order");

Page({
    data: {
        icons: t.requirejs("icons"),
        status: "",
        list: [],
        page: 1,
        code: !1,
        cancel: e.cancelArray,
        cancelindex: 0,
        can_sync_goodscircle: !1,
      imgArr: [
        'https://wash.nemolaundry.com/attachment/images/1/2020/01/H2T0jpB8QtTP007J1vyYBJV0tPtEqj.jpeg',
        'https://wash.nemolaundry.com/attachment/images/1/2020/01/H2T0jpB8QtTP007J1vyYBJV0tPtEqj.jpeg',
        'https://wash.nemolaundry.com/attachment/images/1/2020/01/LYuU6Ye6eBOeOLAYozlTQ6qEee6Ycq.jpg'
      ],
      showModal: false,
      textV: ''
    },
    payurl(res){
      var that = this;
      var url = res.currentTarget.dataset.url;
      a.get("member/getconfig", {}, function (res) {
        console.log(res, 555)
        if (res.flag == 1) {
          t.showError(res.detail);
        } else {
          wx.navigateTo({
            url: url,
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
          })
        }
      })
    },
    previewImg: function (e) {
      console.log(e.currentTarget.dataset.index);
      var listindex = e.currentTarget.dataset.listindex;
      var nogiftindex = e.currentTarget.dataset.nogiftindex;
      var index = e.currentTarget.dataset.index;
      var imgArr = this.data.list[listindex].nogift[nogiftindex].imggs;
      wx.previewImage({
        current: imgArr[index],     //当前图片地址
        urls: imgArr,               //所有要预览的图片的地址集合 数组形式
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    },
    onLoad: function(res) {
      //  var status =  wx.getStorageSync('status');
      //   if (status){
      //     res = status
      //     console.log(res)
      //   }
     
      // wx.removeStorageSync('status')
      console.log(res,888)
        var e = this;
      t.changeTabBar();
        a.get("member/getconfig", {}, function (res) {
          console.log(res, 555)
          if (res.flag == 1) {
            // t.showError(res.detail);
            e.setData({
              showModal: true,
              textV: res.detail
            })
          }
        });
        a.get("member", {}, function(r) {
          console.log(r,4444);
            1 == r.isblack && wx.showModal({
                title: "无法访问",
                content: "您在商城的黑名单中，无权访问！",
                success: function(r) {
                    r.confirm && e.close(), r.cancel && e.close();
                }
            }), e.setData({
                member: r,
            }), r.error;
        });
        // t.checkAuth(), 
        wx.getSetting({
            success: function(s) {
              if(!s.authSetting["scope.userInfo"]){
                e.setData({
                  loading: !1,
                  show: !0,
                  empty: !0,
                })
              }else{
                s.authSetting["scope.userInfo"] && (e.setData({
                  options: res,
                  status: res.status || "",
                    imgUrl: t.globalData.approot
                }), t.url(res),e.get_list());
              }
                
            }
        });
    },
    onShow:function(){
      // var status = wx.getStorageSync('status');
      // if (status) {
      //   var a = status
      //   console.log(a)
      // } else {
      //   var a = {}
      // }
      // wx.removeStorageSync('status')
      
      // var e = this;
      // wx.getSetting({
      //   success: function (s) {
      //     console.log(a.status, 888)
      //     s.authSetting["scope.userInfo"] && (e.setData({
      //       options: a,
      //       status: a.status || "",
      //       imgUrl: t.globalData.approot,
      //       list: [],
      //       page: 1,
      //       code: !1,
      //       cancel: e.cancelArray,
      //       cancelindex: 0,
      //       can_sync_goodscircle: !1
      //     }), t.url(a), e.get_list());
      //   }
      // });
    },
    onHide: function () {
      console.log("==onHide==");
      
    },
    get_list: function() {
        var e = this;
        e.setData({
            loading: !0,
            isgoods: t.globalData.isgoods
        }), a.get("order/get_list", {
            page: e.data.page,
            status: e.data.status,
            merchid: 0
        }, function(t) {
            0 == t.error ? (e.setData({
                loading: !1,
                show: !0,
                total: t.total,
                empty: !0,
                can_sync_goodscircle: t.can_sync_goodscircle
            }), t.list.length > 0 && e.setData({
                page: e.data.page + 1,
                list: e.data.list.concat(t.list)
            }), t.list.length < t.pagesize && e.setData({
                loaded: !0
            })) : a.toast(t.message, "loading");
        }, this.data.show);
    },
    selected: function(t) {
      if(this.data.member.error!='10003'){
        var e = a.data(t).type;
        this.setData({
            list: [],
            page: 1,
            status: e,
            empty: !1
        }), this.get_list();
      }
        
    },
    onReachBottom: function() {
        this.data.loaded || this.data.list.length == this.data.total || this.get_list();
    },
    code: function(t) {
        var e = this, s = a.data(t).orderid;
        a.post("verify/qrcode", {
            id: s
        }, function(t) {
            0 == t.error ? e.setData({
                code: !0,
                qrcode: t.url
            }) : a.alert(t.message);
        }, !0);
    },
    close: function() {
        this.setData({
            code: !1
        });
    },
    cancel: function(t) {
        var s = a.data(t).orderid;
        e.cancel(s, t.detail.value, "/pages/order/index?status=" + this.data.status);
    },
    delete: function(t) {
        var s = a.data(t).type, i = a.data(t).orderid;
        e.delete(i, s, "/pages/order/index", this);
    },
    finish: function(t) {
        a.data(t).type;
        var s = a.data(t).orderid;
        e.finish(s, "/pages/order/index");
    },
    onShareAppMessage: function() {
        return a.onShareAppMessage();
    }
});